﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for ThungRacDA
/// </summary>
public class ThungRacDA
{
    Connection con = new Connection();
	public ThungRacDA()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public void XoaThungRacSP()
    {
        try
        {
            string str = "delete from hinhanh where MaSanPham in (select MaSanPham from SanPham where Xoa <>0)";
            SqlCommand com = new SqlCommand(str, con.getCon());
            con.openCon();
            com.ExecuteNonQuery();
            con.closeCon();
            str = "delete from chitietdonhang where sanphamid in (select MaSanPham from SanPham where Xoa <>0)";
            com = new SqlCommand(str, con.getCon());
            con.openCon();
            com.ExecuteNonQuery();
            con.closeCon();
            str = "delete from SanPham where Xoa <>0";
            com = new SqlCommand(str, con.getCon());
            con.openCon();
            com.ExecuteNonQuery();
            con.closeCon();
        }
        catch (Exception)
        {

            throw;
        }
        finally
        {
            con.closeCon();
        }
    }
    public void XoaThuongRacLoai()
    {
        try
        {
            string str = "delete from hinhanh where MaSanPham in (select MaSanPham from SanPham where LoaiID in (select ID from Loai where Xoa <> 0 ))";
            SqlCommand com = new SqlCommand(str, con.getCon());
            con.openCon();
            com.ExecuteNonQuery();
            con.closeCon();
            str = "delete from chitietdonhang where sanphamid in (select MaSanPham from SanPham where LoaiID in (select ID from Loai where Xoa <> 0 ))";
            com = new SqlCommand(str, con.getCon());
            con.openCon();
            com.ExecuteNonQuery();
            con.closeCon();
            str = "delete from SanPham where LoaiID in (select ID from Loai where Xoa <> 0 )";
            com = new SqlCommand(str, con.getCon());
            con.openCon();
            com.ExecuteNonQuery();
            con.closeCon();
            str = "delete from Loai where Xoa <> 0 ";
            com = new SqlCommand(str, con.getCon());
            con.openCon();
            com.ExecuteNonQuery();
            con.closeCon();
        }
        catch (Exception)
        {
            
            throw;
        }
        finally
        {
            con.closeCon();
        }

    }
    public void XoaThungRacChucNang()
    {
        try
        {
            string str = "delete from hinhanh where MaSanPham in (select MaSanPham from SanPham where ChucNangID in (select ID from Chucnang where Xoa <> 0 ))";
            SqlCommand com = new SqlCommand(str, con.getCon());
            con.openCon();
            com.ExecuteNonQuery();
            con.closeCon();
            str = "delete from chitietdonhang where sanphamid in (select MaSanPham from SanPham where ChucNangID in (select ID from ChucNang where Xoa <> 0 ))";
            com = new SqlCommand(str, con.getCon());
            con.openCon();
            com.ExecuteNonQuery();
            con.closeCon();
            str = "delete from SanPham where ChucNangID in (select ID from ChucNang where Xoa <> 0 )";
            com = new SqlCommand(str, con.getCon());
            con.openCon();
            com.ExecuteNonQuery();
            con.closeCon();
            str = "delete from ChucNang where Xoa <> 0 ";
            com = new SqlCommand(str, con.getCon());
            con.openCon();
            com.ExecuteNonQuery();
            con.closeCon();
        }
        catch (Exception)
        {
            
            throw;
        }
        finally
        {
            con.closeCon();
        }
    }
    public void XoaThungRacThuongHieu()
    {
        try
        {
            string str = "delete from hinhanh where MaSanPham in (select MaSanPham from SanPham where NhanHieuID in (select ID from NhanHieu where Xoa <> 0 ))";
            SqlCommand com = new SqlCommand(str, con.getCon());
            con.openCon();
            com.ExecuteNonQuery();
            con.closeCon();
            str = "delete from chitietdonhang where sanphamid in (select MaSanPham from SanPham where NhanHieuID in (select ID from NhanHieu where Xoa <> 0 ))";
            com = new SqlCommand(str, con.getCon());
            con.openCon();
            com.ExecuteNonQuery();
            con.closeCon();
            str = "delete from SanPham where NhanHieuID in (select ID from NhanHieu where Xoa <> 0 )";
            com = new SqlCommand(str, con.getCon());
            con.openCon();
            com.ExecuteNonQuery();
            con.closeCon();
            str = "delete from NhanHieu where Xoa <> 0 ";
            com = new SqlCommand(str, con.getCon());
            con.openCon();
            com.ExecuteNonQuery();
            con.closeCon();
        }
        catch (Exception)
        {
            
            throw;
        }
        finally
        {
            con.closeCon();
        }
    }
}